/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon
 												
Class							:				SequentialCondition
 
Function						: 				Provides a class for holding a sequential 
												condition 
****************************************************************************/
package planninglanguage.softconditions;

import base.WargusGameState;

public class SequentialSoftCondition extends SoftCondition {

	SoftCondition m_c1,m_c2;
	int m_status;

	public SequentialSoftCondition(SoftCondition a_c1,SoftCondition a_c2)
	{
		m_c1=a_c1;
		m_c2=a_c2;
		m_status=0;
	}
	
	public void reset()
	{
		m_status = 0;
		m_c1.reset();
		m_c2.reset();
	}
	
	public float test(WargusGameState a_gameState) 
	{
		float s1 = 0.0f, s2 = 0.0f;
		if (m_status==0) {
			s1 = m_c1.test(a_gameState); 
			if (s1 >= 1.0f) m_status = 1;
		} else {
			s1 = 1.0f;
		}
		if (m_status==1) {
			s2 = m_c2.test(a_gameState); 
			if ( s2 >= 1.0f) {				
				m_status = 2;
				return 1.0f;
			}
		}
		return (s1 + s2)/2.0f;
	}

	public String toString(int tabs) {
		String str= super.toString(tabs);
		int i;
		
		for(i=0;i<tabs;i++) str = str + "  ";
		str = str +  "SoftSequential( status = \n" + m_status;
		if (m_c1!=null)	{
			str = str + m_c1.toString(tabs+1) + "\n";
		} else {
			for(i=0;i<tabs+1;i++) str = str + "  ";
			str = str +  "null\n";
		}  
		if (m_c2!=null)	{
			str = str + m_c2.toString(tabs+1) + "\n";
		} else {
			for(i=0;i<tabs+1;i++) str = str + "  ";
			str = str +  "null\n";
		}  
		for(i=0;i<tabs;i++) str = str + "  ";
		str = str +  ")";
		return str;
	}	
		
}
